package com.mhg.collection.theList;

import com.mhg.collection.bean.Student;

import java.util.ArrayList;
import java.util.Iterator;



public class Demo_ArrayList_02 {
	public static void main(String[] args){
		ArrayList list = new ArrayList();
		list.add(new Student("张三", 23));
		list.add(new Student("李四", 24));
		list.add(new Student("张三", 23));
		list.add(new Student("王五", 25));
		System.out.println(list);
		ArrayList newList = getSingle(list);
		System.out.println(newList);
	}
	public static ArrayList getSingle(ArrayList list){
		ArrayList newList = new ArrayList();
		Iterator it = list.iterator();
		while(it.hasNext()){
			Object obj = it.next();
			if(!newList.contains(obj)){
				newList.add(obj);
			}
		}
		return newList;
	}
}
